#include<iostream>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
#include<cstring>
#include<string>

using namespace std;
#define BUFFSIZE 1024
#define FILEMOD 0666
char buff[BUFFSIZE];
const char *FINENAME = "./fifo_file";

int main(){
    int fd = open(FINENAME,O_RDONLY,FILEMOD);
    if(-1 == fd){
        cout<<"open : "<<strerror(errno)<<endl;
        exit(errno);
    }
    while(1){
        int n = read(fd,buff,BUFFSIZE);//管道空就阻塞,写端关闭就读空,与匿名管道一样
        if(-1 == n){
            perror("read");
            exit(errno);
        }
        buff[n] = '\0';
        if(n==0) break;
        cout<<buff<<endl;
    }

    close(fd);
    return 0;
}